# from die import Die
#
# # 创建一个D6
# die = Die()
#
# # 投掷几次骰子并将结果存储在一个列表中
# results = []
# for roll_num in range(1000):
#     result = die.roll()
#     results.append(result)
#
# # print(results)
#
# # 分析结果
# frequencies = []
# poss_results = range(1, die.num_sides + 1)
# for value in poss_results:
#     frequency = results.count(value)
#     frequencies.append(frequency)
#
# # print(frequencies)
#
# # 对结果进行可视化
#
# import plotly.express as px
#
# title = "Result of Rolling One D6 1000 Times"
# labels = {'x': 'Result', 'y': 'Frequency of Result'}
# fig = px.bar(x=poss_results, y=frequencies,title=title, labels=labels)
#
# fig.show()


from die import Die

# 创建两个D6
die_1 = Die()
die_2 = Die(10)

# 投掷几次骰子并将结果存储在一个列表中
results = []
for roll_num in range(50_000):
    result = die_1.roll() + die_2.roll()
    results.append(result)

# 分析结果
max_result = die_1.num_sides + die_2.num_sides
frequencies = []
poss_results = range(1, max_result + 1)
for value in poss_results:
    frequency = results.count(value)
    frequencies.append(frequency)

# 对结果进行可视化

import plotly.express as px

title = "Result of Rolling Two D6 Dice 1000 Times"
labels = {'x': 'Result', 'y': 'Frequency of Result'}
fig = px.bar(x=poss_results, y=frequencies,title=title, labels=labels)

# 进一步定制图形
fig.update_layout(xaxis_dtick=1) # xaxis_dtick指定x轴上刻度标记的间距

fig.show()

# fig.write_html('dice_visual_d6d10.html') # 通过浏览器将其保存为HTML文件


